package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysRole;
import io.mybatis.example.springboot.service.SysRoleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_role - 角色信息表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysRoles")
public class SysRoleController {

  @Autowired
  private SysRoleService sysRoleService;

  @PostMapping
  public DataResponse<SysRoleDO> save(@RequestBody SysRoleDO sysRole) {
    return DataResponse.ok(sysRoleService.save( sysRole));
  }

  @GetMapping
  public RowsResponse<SysRoleDO> findList(@RequestBody SysRoleDO sysRole) {
    return RowsResponse.ok(sysRoleService.findList( sysRole));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysRoleDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysRoleService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysRoleDO> update(@PathVariable("id") Long id, @RequestBody SysRoleDO sysRole) {
    sysRole.setId(id);
    return DataResponse.ok(sysRoleService.update( sysRole));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysRoleService.deleteById(id) == 1);
  }

}
